package com.sun.kamun.config;

import com.sun.kamun.entity.OrderDetails;
import com.sun.kamun.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class OrderTimeOutCancelListener {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = RabbitMQConfig.DEAD_LETTER_QUEUE)
    public void processExpiredOrder(OrderDetails orderDetails) {
        String orderId = orderDetails.getOrderId();
        // 检查订单是否已支付
        if (orderService.getById(orderId).getOrderStatus()!=0) {
            // 执行订单取消的业务逻辑
            orderDetails.setOrderStatus(4);
            orderService.updateById(orderDetails);
        }
    }
}
